package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.UserCoverUrl;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserCoverUrlDao {
    @Resource
    private SqlSession sqlSession;

    /**
     * 查询用户封面列表
     * @param userId
     * @param state 状态0:所有 1:通过 2:审核中
     * @return
     */
    @Operate("strategy('byUserId', #userId)")
    public List<UserCoverUrl> getUserCoverUrlByUserId(long userId,int state) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("userId", userId);
        map.put("state", state);
        return sqlSession.selectList("getUserCoverUrlByUserId", map);
    }

    @Operate("strategy('byUserId', #userId)")
    public int deleteUserCoverUrl(int id, long userId) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("id", id);
        map.put("userId", userId);
        return sqlSession.delete("deleteUserCoverUrl", map);
    }
    @Operate("strategy('byVideoId',#entity.userId)")
    public int insertUserCoverUrl(UserCoverUrl entity) {
        return sqlSession.insert("insertUserCoverUrl", entity);
    }
    @Operate("strategy('byUserId', #userId)")
    public int findCoverNumByUserId(long userId) {
        return sqlSession.selectOne("findCoverNumByUserId",userId);
    }

    @Operate("strategy('byUserId', #userId)")
    public List<UserCoverUrl> selectUserCoverUrlPage(Long userId, int startNum, int pageSize) {
        Map<String,Object> params = new HashMap<>(3);
        params.put("userId",userId);
        params.put("startNum",startNum);
        params.put("pageSize",pageSize);
        return sqlSession.selectList("selectUserCoverUrlPage",params);
    }
}
